package ttsolver.constraints;

import ttsolver.input.Track;
import ttsolver.input.Train;

public class ConsTempoEspaco2 extends DefaultConstraint {

	private Train train;
	private Track track;
	private int initTime;
	private int endTime;

	public ConsTempoEspaco2() {
		super(ConstraintType.CONS_TEMPO_ESPACO);
	}

	public ConsTempoEspaco2(Train train, Track track,  int initTime, int endTime) {
		super(ConstraintType.CONS_TEMPO_ESPACO);
		this.train = train;
		this.track = track;
		this.initTime = initTime;
		this.endTime = endTime;
	}
	
	public Train getTrain() {
		return train;
	}

	public void setTrain(Train train) {
		this.train = train;
	}

	public Track getTrack() {
		return track;
	}

	public void setTrack(Track track) {
		this.track = track;
	}

	public int getInitTime() {
		return initTime;
	}

	public void setInitTime(int initTime) {
		this.initTime = initTime;
	}

	public int getEndTime() {
		return endTime;
	}

	public void setEndTime(int endTime) {
		this.endTime = endTime;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		ConsTempoEspaco2 other = (ConsTempoEspaco2) obj;

		if (train == null) {
			if (other.train != null)
				return false;
		} else if (!train.equals(other.train)) {
			return false;
		}
		
		if (track.getNodeOne() == null) {
			if (other.track.getNodeOne() != null)
				return false;
		} else if (!track.getNodeOne().equals(other.track.getNodeOne())) {
			return false;
		}
		
		if (track.getNodeTwo() == null) {
			if (other.track.getNodeTwo() != null)
				return false;
		} else if (!track.getNodeTwo().equals(other.track.getNodeTwo())) {
			return false;
		}
		
		if (initTime != other.initTime) {
			return false;
		}
		
		if (endTime != other.endTime) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		String s = "";
		s += (train != null) ? train.getId() : "N/A";
		s += (track.getNodeOne() != null) ? "," + track.getNodeOne().getId() : "N/A";
		s += (track.getNodeTwo() != null) ? "," + track.getNodeTwo().getId() : "N/A";
		s += "," + initTime;
		s += "," + endTime;
		return "Bloqueio_(" + s + "):\n";
	}

}
